package org.example.java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 夏焰波
 * @date 2020-07-12 22:32
 */
public class StreamFilter {

    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 7, 7, 1);
        //过滤，取偶数
        List<Integer> result = list.stream().filter(i -> i % 2 == 0).collect(Collectors.toList());
        System.out.println(result);

        //去重
        result = list.stream().distinct().collect(Collectors.toList());
        System.out.println(result);

        //截取前边5个
        result = list.stream().limit(5).collect(Collectors.toList());
        System.out.println(result);
        //跳过前边5个
        result = list.stream().skip(5).collect(Collectors.toList());
        System.out.println(result);

    }
}
